package phone

import (
	"fmt"
	"hft/Database/admin/user_db"
	"hft/Http/Services/phone/phone_dao"
	"hft/Http/Services/phone/phone_utils"
	"hft/global"
	"hft/tools"
)

type PhoneCallLog struct{}

// 生成400线索
func (*PhoneCallLog) Add(data *user_db.PhoneRecord) (err error) {
	fmt.Println(tools.JsonParse(data))
	city, err := phone_utils.FindCity(data.City)
	if err != nil {
		return err
	}
	// 先找出客户是否存在
	user, err := phone_dao.FindUser(data, int(city.ID), global.OC_DB)
	if err != nil {
		// 客户不存在就创建
		phone_dao.CreateUser(data, int(city.ID), global.OC_DB)
	} else {
		// 存在就直接加记录
		phone_dao.AddClue(global.OC_DB, user, data)
	}
	return nil
}

var PhoneCallLogService = new(PhoneCallLog)
